<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Board/nrf6310/esb/esb_ptx_prx/main_esb_ptx_ack_payload.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>



<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF Enhanced Shockburst
   &#160;<span id="projectnumber">version 0.4.2</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('main__esb__ptx__ack__payload_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Board/nrf6310/esb/esb_ptx_prx/main_esb_ptx_ack_payload.c</div>  </div>
</div>
<div class="contents">
<a href="main__esb__ptx__ack__payload_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment">*</span>
<a name="l00003"></a>00003 <span class="comment">* The information contained herein is property of Nordic Semiconductor ASA.</span>
<a name="l00004"></a>00004 <span class="comment">* Terms and conditions of usage are described in detail in NORDIC</span>
<a name="l00005"></a>00005 <span class="comment">* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment">*</span>
<a name="l00007"></a>00007 <span class="comment">* Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment">* WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment">* the file.</span>
<a name="l00010"></a>00010 <span class="comment">*</span>
<a name="l00011"></a>00011 <span class="comment">* $LastChangedRevision: 14207 $</span>
<a name="l00012"></a>00012 <span class="comment">*/</span>
<a name="l00013"></a>00013 
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;<a class="code" href="nrf__esb_8h.html" title="Enhanced ShockBurst API.">nrf_esb.h</a>&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;nrf_gpio.h&quot;</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="comment">/*****************************************************************************/</span>
<a name="l00039"></a>00039 <span class="comment">/*****************************************************************************/</span>
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="comment">// Define pipe</span>
<a name="l00042"></a><a class="code" href="group__esb__ptx__example.html#gae28843c923b3481f8a94798e7ccba523">00042</a> <span class="preprocessor">#define PIPE_NUMBER 0 ///&lt; We use pipe 0 in this example</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span>
<a name="l00044"></a>00044 <span class="comment">// GPIO</span>
<a name="l00045"></a><a class="code" href="group__esb__ptx__example.html#ga2a2f690f8bdeeb4003203ff5e3edaffc">00045</a> <span class="preprocessor">#define BUTTONS NRF_GPIO_PORT_SELECT_PORT0 ///&lt; GPIO port for reading from buttons</span>
<a name="l00046"></a><a class="code" href="group__esb__ptx__example.html#ga61686d33603491344883775b9b31e172">00046</a> <span class="preprocessor"></span><span class="preprocessor">#define LEDS    NRF_GPIO_PORT_SELECT_PORT1 ///&lt; GPIO port for writing to LEDs</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span>
<a name="l00048"></a>00048 <span class="comment">// Define payload length</span>
<a name="l00049"></a><a class="code" href="group__esb__ptx__example.html#gaed1097d348540e6d609ced933dfaa26b">00049</a> <span class="preprocessor">#define TX_PAYLOAD_LENGTH 1 ///&lt; We use 1 byte payload length when transmitting</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a>00051 <span class="comment">// Data and acknowledgement payloads</span>
<a name="l00052"></a><a class="code" href="group__esb__ptx__example.html#ga996dd574db6502532d3ca245aa0dd8f8">00052</a> <span class="keyword">static</span> uint8_t <a class="code" href="group__esb__ptx__example.html#ga996dd574db6502532d3ca245aa0dd8f8" title="Payload to send to PRX.">my_tx_payload</a>[<a class="code" href="group__esb__ptx__example.html#gaed1097d348540e6d609ced933dfaa26b" title="We use 1 byte payload length when transmitting.">TX_PAYLOAD_LENGTH</a>];                
<a name="l00053"></a><a class="code" href="group__esb__ptx__example.html#gacf06a0a946eb250ed4f20248181eb3c4">00053</a> <span class="keyword">static</span> uint8_t <a class="code" href="group__esb__ptx__example.html#gacf06a0a946eb250ed4f20248181eb3c4" title="Placeholder for received ACK payloads from PRX.">my_rx_payload</a>[<a class="code" href="group__esb__02__api.html#ga6fb1ece47082353129db90fd919fe0d2" title="Maximum allowed payload length in bytes.">NRF_ESB_CONST_MAX_PAYLOAD_LENGTH</a>]; 
<a name="l00054"></a>00054 
<a name="l00058"></a>00058 <span class="comment">/*****************************************************************************/</span>
<a name="l00064"></a>00064 <span class="comment">/*****************************************************************************/</span>
<a name="l00065"></a><a class="code" href="group__esb__ptx__example.html#gae66f6b31b5ad750f1fe042a706a4e3d4">00065</a> <span class="keywordtype">int</span> <a class="code" href="group__esb__prx__example.html#gae66f6b31b5ad750f1fe042a706a4e3d4" title="Main function.">main</a>()
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067     <span class="comment">// Setup port directions</span>
<a name="l00068"></a>00068     <a class="code" href="group__nrf__gpio.html#gaaa72c88a2a29927a1eeff691d6a21afc" title="Set the direction of a port.">nrf_gpio_port_dir_set</a>(<a class="code" href="group__esb__ptx__example.html#ga2a2f690f8bdeeb4003203ff5e3edaffc" title="GPIO port for reading from buttons.">BUTTONS</a>, <a class="code" href="group__nrf__gpio.html#gga494d7ac30db1cbb6366e0b9ebd5b49b4a6ec5811669635e30b9dc014e1f494936" title="Input.">NRF_GPIO_PORT_DIR_INPUT</a>);
<a name="l00069"></a>00069     <a class="code" href="group__nrf__gpio.html#gaaa72c88a2a29927a1eeff691d6a21afc" title="Set the direction of a port.">nrf_gpio_port_dir_set</a>(<a class="code" href="group__esb__ptx__example.html#ga61686d33603491344883775b9b31e172" title="GPIO port for writing to LEDs.">LEDS</a>, <a class="code" href="group__nrf__gpio.html#gga494d7ac30db1cbb6366e0b9ebd5b49b4a90b7ce7a76775cb7534487635755be3f" title="Output.">NRF_GPIO_PORT_DIR_OUTPUT</a>);
<a name="l00070"></a>00070 
<a name="l00071"></a>00071     <span class="comment">// Initialize ESB</span>
<a name="l00072"></a>00072     (void)<a class="code" href="group__esb__02__api.html#ga155377fe2e8a0b40352c21a5ec7979ec" title="Initialize ESB.">nrf_esb_init</a>(<a class="code" href="group__esb__02__api.html#gga86fb552224a080814a7e3ac856b57be3a0fc486926b06e9107d3f7459532f7713" title="Primary Transmitter mode.">NRF_ESB_MODE_PTX</a>);
<a name="l00073"></a>00073 
<a name="l00074"></a>00074     (void)<a class="code" href="group__esb__02__api.html#gaa7f7be8b058378a3b31d38ce88e0600f" title="Enable ESB.">nrf_esb_enable</a>();  
<a name="l00075"></a>00075 
<a name="l00076"></a>00076     <span class="comment">// Add packet into TX queue</span>
<a name="l00077"></a>00077     <a class="code" href="group__esb__ptx__example.html#ga996dd574db6502532d3ca245aa0dd8f8" title="Payload to send to PRX.">my_tx_payload</a>[0] = <a class="code" href="group__nrf__gpio.html#ga40bee84dc81b9f8981eb2647dac9d267" title="Read GPIO port.">nrf_gpio_port_read</a>(<a class="code" href="group__esb__ptx__example.html#ga2a2f690f8bdeeb4003203ff5e3edaffc" title="GPIO port for reading from buttons.">BUTTONS</a>);
<a name="l00078"></a>00078     (void)<a class="code" href="group__esb__02__api.html#ga23388e992626680973998c4485ab680a" title="Add a packet to the tail of the TX FIFO.">nrf_esb_add_packet_to_tx_fifo</a>(<a class="code" href="group__esb__ptx__example.html#gae28843c923b3481f8a94798e7ccba523" title="We use pipe 0 in this example.">PIPE_NUMBER</a>, <a class="code" href="group__esb__ptx__example.html#ga996dd574db6502532d3ca245aa0dd8f8" title="Payload to send to PRX.">my_tx_payload</a>, <a class="code" href="group__esb__ptx__example.html#gaed1097d348540e6d609ced933dfaa26b" title="We use 1 byte payload length when transmitting.">TX_PAYLOAD_LENGTH</a>, <a class="code" href="group__esb__02__api.html#gga22b4239274a204804ec90a75464af66ca5e01e008cf46eeb426a18660bff8523c" title="PTX packet requires ACK.">NRF_ESB_PACKET_USE_ACK</a>);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080     <span class="keywordflow">while</span>(1)
<a name="l00081"></a>00081     {
<a name="l00082"></a>00082         <span class="comment">// Optionally set the CPU to sleep while waiting for a callback.</span>
<a name="l00083"></a>00083         <span class="comment">// __WFI();</span>
<a name="l00084"></a>00084     }
<a name="l00085"></a>00085 }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 <span class="comment">/*****************************************************************************/</span>
<a name="l00090"></a>00090 <span class="comment">/*****************************************************************************/</span>
<a name="l00091"></a>00091 
<a name="l00092"></a>00092 
<a name="l00093"></a>00093 <span class="comment">// If an ACK was received, we send another packet. </span>
<a name="l00094"></a><a class="code" href="group__esb__ptx__example.html#ga416a6ef0fc94e7df9054e71c8784095a">00094</a> <span class="keywordtype">void</span> <a class="code" href="group__esb__02__api.html#ga416a6ef0fc94e7df9054e71c8784095a" title="TX success callback.">nrf_esb_tx_success</a>(uint32_t tx_pipe, int32_t rssi){
<a name="l00095"></a>00095     <span class="comment">// Read buttons and load data payload into TX queue</span>
<a name="l00096"></a>00096     <a class="code" href="group__esb__ptx__example.html#ga996dd574db6502532d3ca245aa0dd8f8" title="Payload to send to PRX.">my_tx_payload</a>[0] = <a class="code" href="group__nrf__gpio.html#ga40bee84dc81b9f8981eb2647dac9d267" title="Read GPIO port.">nrf_gpio_port_read</a>(<a class="code" href="group__esb__ptx__example.html#ga2a2f690f8bdeeb4003203ff5e3edaffc" title="GPIO port for reading from buttons.">BUTTONS</a>);  
<a name="l00097"></a>00097     (void)<a class="code" href="group__esb__02__api.html#ga23388e992626680973998c4485ab680a" title="Add a packet to the tail of the TX FIFO.">nrf_esb_add_packet_to_tx_fifo</a>(<a class="code" href="group__esb__ptx__example.html#gae28843c923b3481f8a94798e7ccba523" title="We use pipe 0 in this example.">PIPE_NUMBER</a>, <a class="code" href="group__esb__ptx__example.html#ga996dd574db6502532d3ca245aa0dd8f8" title="Payload to send to PRX.">my_tx_payload</a>, <a class="code" href="group__esb__ptx__example.html#gaed1097d348540e6d609ced933dfaa26b" title="We use 1 byte payload length when transmitting.">TX_PAYLOAD_LENGTH</a>, <a class="code" href="group__esb__02__api.html#gga22b4239274a204804ec90a75464af66ca5e01e008cf46eeb426a18660bff8523c" title="PTX packet requires ACK.">NRF_ESB_PACKET_USE_ACK</a>);
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 <span class="comment">// If the transmission failed, send a new packet.</span>
<a name="l00102"></a><a class="code" href="group__esb__ptx__example.html#ga03993c4e0419bbcac77aa0965ecce6ad">00102</a> <span class="keywordtype">void</span> <a class="code" href="group__esb__02__api.html#ga03993c4e0419bbcac77aa0965ecce6ad" title="TX failed callback (PTX mode only).">nrf_esb_tx_failed</a>(uint32_t tx_pipe){
<a name="l00103"></a>00103     (void)<a class="code" href="group__esb__02__api.html#ga23388e992626680973998c4485ab680a" title="Add a packet to the tail of the TX FIFO.">nrf_esb_add_packet_to_tx_fifo</a>(<a class="code" href="group__esb__ptx__example.html#gae28843c923b3481f8a94798e7ccba523" title="We use pipe 0 in this example.">PIPE_NUMBER</a>, <a class="code" href="group__esb__ptx__example.html#ga996dd574db6502532d3ca245aa0dd8f8" title="Payload to send to PRX.">my_tx_payload</a>, <a class="code" href="group__esb__ptx__example.html#gaed1097d348540e6d609ced933dfaa26b" title="We use 1 byte payload length when transmitting.">TX_PAYLOAD_LENGTH</a>, <a class="code" href="group__esb__02__api.html#gga22b4239274a204804ec90a75464af66ca5e01e008cf46eeb426a18660bff8523c" title="PTX packet requires ACK.">NRF_ESB_PACKET_USE_ACK</a>);}
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 
<a name="l00106"></a><a class="code" href="group__esb__ptx__example.html#gab3042dde4c3151c1517f4998378f52ce">00106</a> <span class="keywordtype">void</span> <a class="code" href="group__esb__02__api.html#gab3042dde4c3151c1517f4998378f52ce" title="RX data ready callback.">nrf_esb_rx_data_ready</a>(uint32_t rx_pipe, int32_t rssi){
<a name="l00107"></a>00107     uint32_t my_rx_payload_length;
<a name="l00108"></a>00108     <span class="comment">// Pop packet and write first byte of the payload to the GPIO port.</span>
<a name="l00109"></a>00109     (void)<a class="code" href="group__esb__02__api.html#gaef1dcdb47f1c29b01badecdeb6fb3459" title="Fetch a packet from the head of the RX FIFO.">nrf_esb_fetch_packet_from_rx_fifo</a>(<a class="code" href="group__esb__ptx__example.html#gae28843c923b3481f8a94798e7ccba523" title="We use pipe 0 in this example.">PIPE_NUMBER</a>, <a class="code" href="group__esb__ptx__example.html#gacf06a0a946eb250ed4f20248181eb3c4" title="Placeholder for received ACK payloads from PRX.">my_rx_payload</a>, &amp;my_rx_payload_length);  
<a name="l00110"></a>00110     <span class="keywordflow">if</span> (my_rx_payload_length &gt; 0)
<a name="l00111"></a>00111     {
<a name="l00112"></a>00112         <a class="code" href="group__nrf__gpio.html#gac1d4940bc5ad4aad4f6363c7021b08ae" title="Write GPIO port.">nrf_gpio_port_write</a>(<a class="code" href="group__esb__ptx__example.html#ga61686d33603491344883775b9b31e172" title="GPIO port for writing to LEDs.">LEDS</a>, ~<a class="code" href="group__esb__ptx__example.html#gacf06a0a946eb250ed4f20248181eb3c4" title="Placeholder for received ACK payloads from PRX.">my_rx_payload</a>[0]); <span class="comment">// Button press is active low.</span>
<a name="l00113"></a>00113     }
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="comment">// Callbacks not needed in this example.</span>
<a name="l00117"></a><a class="code" href="group__esb__ptx__example.html#ga5e82709bd23aa952a883db3af5b987e0">00117</a> <span class="keywordtype">void</span> <a class="code" href="group__esb__02__api.html#ga5e82709bd23aa952a883db3af5b987e0" title="Disabled callback.">nrf_esb_disabled</a>(<span class="keywordtype">void</span>)
<a name="l00118"></a>00118 {}
<a name="l00119"></a>00119 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="main__esb__ptx__ack__payload_8c.html">main_esb_ptx_ack_payload.c</a>      </li>

    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
